package com.cf.end.cowboy;

import com.cf.game.service.util.BeanFactoryUtil;
import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;

/**
 * cf-game-BusinessEndPointAdapter
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/3/27 21:10
 */
@Component
@ServerEndpoint(value = "/nz")
public class CowBoyEndPointAdapter {

    /**
     * 连接建立成功调用的方法
     */
    @OnOpen
    public void onOpen(Session session) {
        BeanFactoryUtil.getBean("cowboy", CowBoyEndPoint.class).onOpen(session);
    }

    /**
     * 连接关闭调用的方法
     */
    @OnClose
    public void onClose(Session session) {
        BeanFactoryUtil.getBean("cowboy", CowBoyEndPoint.class).onClose(session);
    }

    /**
     * 收到客户端消息后调用的方法
     *
     * @param message 客户端发送过来的消息
     */
    @OnMessage
    public void onMessage(String message, Session session) throws IOException {
        BeanFactoryUtil.getBean("cowboy", CowBoyEndPoint.class).onMessage(message, session);
    }


    @OnError
    public void onError(Session session, Throwable error) {
        BeanFactoryUtil.getBean("cowboy", CowBoyEndPoint.class).onError(session, error);
    }

}
